#ifndef IAP_H
#define IAP_H

#include "iap/include/iap_file.h"
#include "iap/include/iap_udp.h"
#include <functional>

void IapDefault_ShowMsg(QString msg);

class Iap
{
public:
    Iap(std::function<void(QString)> showMsg = IapDefault_ShowMsg);
    ~Iap();
    bool SetHd(const QString &name);
    bool SetIo(QHostAddress localIp, quint16 localPort, QHostAddress sendIp, quint16 sendPort);
    void Init();
    void Close();
    int32_t ReadIo(uint8_t * pdata, int32_t len);
    int32_t WriteIo(uint8_t * pdata, int32_t len);
    int32_t ReadHd(uint8_t * pdata, int32_t len);
    int32_t WriteHd(uint8_t * pdata, int32_t len);
    QByteArray Md5();
    /* file send and receive */
    qint32 Send();
    qint32 Recv();
private:
    bool __WaitForData(QByteArray tData, qint32 timeout);
    bool __FindData(QByteArray & rData, qint32 len, QByteArray & tData);
    QString __ToHexString(QByteArray md5);
    IapFile __hd;
    IapUdp  __io;
    std::function<void(QString)> __showMsg;
};

#endif // IAP_H
